home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ham Radio 2000
/
Ham Radio 2000.iso
/
ham2000
/
packet
/
p_tapr
/
tnchst
/
ax25.c
< prev
next >
Wrap
Text File
|
1990-06-04
|
4KB
|
195 lines
/*** display function for aft test ****/
#define AX25_ADDRLEN 7
void moncall( callptr )
byte *callptr;
{
int x;
/* display callsign */
for ( x = 0 ; x < AX25_ADDRLEN-1 ; ++x )
printf("%c", (*callptr++) >> 1 );
}
void monframe( ptr, len )
byte *ptr; /* points to 1st byte of aft frame */
int len; /* length */
{
putchar('\n');
moncall( ptr+AX25_ADDRLEN ); /* source call */
putchar('>');
moncall( ptr ); /* dest */
len -= (AX25_ADDRLEN * 2);
ptr += (AX25_ADDRLEN * 2);
while ( (*(ptr-1) & 1) == 0 && /* do while all calls not displayed */
len > 0 ) /* and length is gt 0 in case not
ax25 */
{
moncall( ptr ) ; /* display a callsign */
putchar(',');
ptr += AX25_ADDRLEN ; /* point to next callsign */
len -= AX25_ADDRLEN;
};
putchar(':');
/** pointer is now pointing to cmd byte **/
if ( *ptr == 03 || (*ptr & 1) == 0 ) /** if unproto or info **/
{
len -= 2 ; /** adj len for cmd & pid **/
ptr += 2 ;
while ( len-- > 0 ) /** while chars to display **/
{
if (*ptr == 0x0d )
putchar('\n'); /* map cr's to newlines */
else
putchar( *ptr ); /** print !cr's **/
++ptr;
}
}
else /* else not data packet */
printf("cmd: %02X",*ptr);
putchar('\n');
}
/**** aux routines from loh ****/
makupper(c)
char *c;
{
*c = toupper( *c );
}
iswhite( c )
char c;
{
static word result ;
switch ( c )
{
case ' ':
case ',':
case '\n':
case '\r':
case NULL:
result = TRUE ; break ;
default:
result = FALSE ;
}
return result ;
}
byte *atocall( buffer , chr )/* converts text callsign pointed to and returns
pointer to char AFTER last ssid char if
call was okay */
byte *buffer;
char *chr;
{
int is_ok ;
/* set to FALSE when bad call character encountered */
int len ; /* # chars allowed in "text" portion */
char *wk ; /* work pointer */
int ssid ; /* hold ssid here when it is called for */
is_ok = TRUE ; /* assume okay */
len = AX25_ADDRLEN - 1 ; /* init with # of characters allowed*/
wk = buffer ; /* set up build ptr */
while (is_ok && *chr && len)/* while more chars to cvt & len valid */
{
if ( *chr == '-' || iswhite( *chr ) )
break ; /*white space or hyphen here?*/
makupper( chr );
if ( *chr >= 'A' && *chr <='Z' || isdigit( *chr ) )
/* if valid */
{
*wk++ = *chr++ << 1 ; /* move call */
}
else /* else not valid char */
is_ok = FALSE ; /* turn bad flag on */
end_if
--len ; /* count a shifted character */
} /*endwhile*/
if ( !is_ok || len == AX25_ADDRLEN - 1 )
/* if not ok or nothing converted or 6 chars cnvtd */
return FALSE ; /* return if was bad */
/* else valid up till now, perhaps there is also an
ssid. first get the ssid (if any), then pad the
built callsign if that is needed */
ssid = 0x60 ; /* assume null ssid */
switch ( *chr++ ) /* if hyphen indicates ssid then */
{ case '-':
if ( !isdigit( *chr ) )
is_ok = FALSE ;
else
{
ssid = *chr++ & 15 ; /*** 0-9 ssid only!! ***/
if ( isdigit( *chr ) )
{
ssid *= 10 ;
ssid += *chr++ & 15 ;
}
is_ok = ( ssid <<= 1 ) < 32 ; /* validate ssid */
ssid |= 0x60 ;
}
break;
case NULL:
--chr; break;
default:
if ( !iswhite( *--chr ) ) /* garbage here after call */
is_ok = FALSE ; /* else set error cuz no hyphen
yet more */
else ; /* else its whitespace and can continue or end */
} /* end switch */
/* pad */
while ( len-- ) /* while there are empty spots in call */
*wk++ = ' ' << 1 ;
*wk++ = ssid ; /* write ssid byte, no E set */
*wk++ = NULL ;
return ( is_ok ? chr : FALSE ); /* return with ptr to nx call or
NIL if error */
}
char *calltoa( buffer , call ) /* convert call to ascii, result to buffer */
byte *buffer;
char *call; /* char after ssid pointed to in return arg */
{
register int i ;
char *pssid;
pssid = call + AX25_ADDRLEN - 1 ; /* pointer to ssid byte */
i = 0 ;
while ( i++ < AX25_ADDRLEN-1 && *call != ' ' << 1 )
*buffer++ = *call++ >> 1 ;
if ( i = *pssid >> 1 & 15 ) /* if ssid != 0 */
sprintf( buffer , "-%d" , i ) ;
else
*buffer = NULL ; /* else put null here */
end_if
return ( pssid + 1 );
}